<template>
  <div>
    <div
      class="wrapper-container"
      style="display: flex; flex-direction: column; width: 100%"
    >
      <div class="search-container">
        <div class="search-container-left">
          <div
            class="search-container-item"
            v-for="(select, index) in selectList"
            :key="index"
          >
            <div v-if="select.type === 'select'" class="box">
              <span v-show="select.name">{{ select.name }}</span>

              <el-select
                v-model="select.val"
                style="width: 90px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
            <div class="box" v-if="select.type === 'data'">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-date-picker
                v-model="select.val"
                type="date"
                placeholder="选择日期"
                prefix-icon="aaa"
              >
              </el-date-picker>
            </div>
            <div v-if="select.type === 'MultiSelect'" class="box"></div>
            <div v-if="select.type === 'btn'" class="box">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-input
              style="width:120px"
                v-model="select.val"
                placeholder="请输入内容"
              ></el-input>
            </div>
          </div>
          <div class="search-button" style="margin-left: 20px" @click="queryStudentList()">
            <img src="../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
        </div>
      </div>
    </div>

    <div class="n-query-block" v-for="(item,index) in listData" :key="index">
      <div class="title">{{item.zybc}}</div>
      <div class="cont-table">
        <div class="cont-item"  v-for="(list,inx) in item.xyList" :key="inx">{{list.name}} ({{list.code}}) {{list.ms}}门</div>
      </div>
    </div>

    <div class="export-top" style="margin:20px" @click="exportData()">
        <img src="../../../../assets/assessment/icon-export.png" alt="" />
        <span>&ensp;导出Excel</span>
      </div>
    </div>

</template>

<script>

import {xxk_getXkXyN, queryCommonPycc, queryCommonXueqi, xxk_exportXkXyN, queryDefaultXueQi} from "@/api/trainingManagement/place.js";
export default {
  data() {
    return {
      listData: [], //
      selectList: [
        {
          type: "select",
          name: "学期:",
          val: "",
          valList: [],
        },
        {
          type: "select",
          name: "培养层次：",
          val: "",
          valList: [],
        },
        {
          type: "btn",
          name: "选课门数少于：",
          val: "",
        },
      ],
    };
  },
  created() {},
  mounted() {
    this.getDefaultXueQi();
    this.queryCommonPycc();
    this.queryCommonXueqi();
  },
  methods: {
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.selectList[0].val = res.data.data;
        }
      })
    },
    exportData() {
      var xueqi = this.selectList[0].val;
      var pycc = this.selectList[1].val;
      var ms = this.selectList[2].val;
      if (ms == "" || ms == null) {
        this.$message.warning("请先输入门数!");
        return;
      }
      xxk_exportXkXyN(xueqi, pycc, ms).then((res) => {
        /** 获取生成设置好的文件名 */
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "选课门数少于N门学员.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    async queryStudentList() {
      var xueqi = this.selectList[0].val;
      var pycc = this.selectList[1].val;
      var ms = this.selectList[2].val;
      if (ms == "" || ms == null) {
        this.$message.warning("请先输入门数!");
        return;
      }
      const res = await xxk_getXkXyN(xueqi, pycc, ms);
      if (res.data.code == 200) {
        this.listData = res.data.data;
      }
    },
    // 获取培养层次列表
    async queryCommonPycc() {
      const res = await queryCommonPycc();
      if (res.data.code == 200) {
        this.selectList[1].valList = res.data.data;
        // this.selectList[1].val = this.selectList[1].valList[0].id;
      }
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.selectList[0].valList = res.data.data;
      }
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 15%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.search-button {
  width: 77px;
  height: 28px;
  line-height: 28px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  > span {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }
  > img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
  }
}

.n-query-block {
  margin: 20px auto 0;
  width: calc(100% - 20px);
  color: #004ca7;

  .title {
    margin: 10px;
    font-size: 16px;
    font-weight: bold;
  }
  .cont-table {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid;
    border-radius: 5px;
    .cont-item:nth-child(n) {
      width: 20%;
      height: 80px;
      border-bottom: 1px solid #004ca7;
      border-right: 1px solid #004ca7;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .cont-item:nth-child(5n) {
      border-right: 0;
    }
  }
}

.export-top {
  cursor: pointer;
  width: 127px;
  height: 27px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 4px;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  flex-direction: row;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: center;
  justify-content: center;
  > img {
    width: 17px;
    height: 17px;
  }
  >span {
    color: #f3b815;
  }
}
</style>
